//app.js
 
App({
  onLaunch: function (opt) {
    var that = this;
      var userInfoLocal = false;
      wx.getStorage({
          key:'userInfo',
          success:function (res) {
              console.log(res.data)
              userInfoLocal = JSON.parse(res.data)
              that.globalData.userInfo = userInfoLocal;
              console.log(userInfoLocal)
              that.globalData.hasUserInfo = true
          }
      })
      console.log('群场景shareTicket',opt.scene)
    if(opt.scene == 1044){
      console.log('群场景shareTicket',opt.shareTicket)
        that.globalData.shareTicket = opt.shareTicket
    }
    var resetShareData = function () {
      var myTime = new Date();
      var today = myTime.getDate();
      
      wx.getStorage({
        key:'shareObj',
        success:function (res) {
          var shareObj =JSON.parse( res.data)
          console.log('shareObj',shareObj)
          if (today != shareObj.day){
            shareObj= {
              day:today,
              shareTime :3
            }
          }
          wx.setStorage({
            key:'shareObj',
            data:JSON.stringify(shareObj)
          })
          that.globalData.shareObj = shareObj
          
        },fail:function (res) {
          console.log(res)
          var shareObj = {
            day:today,
            shareTime:3
          }
          wx.setStorage({
            key:'shareObj',
            data:JSON.stringify(shareObj)
          })
          that.globalData.shareObj = shareObj
        }
      })
      
    }
    resetShareData()
    wx.request({
      url: 'https://res7.sanliwenhua.com/song2.json', //仅为示例，并非真实的接口地址
      // data: {
      //    x: '' ,
      //    y: ''
      // },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        var data = res.data.data;
        var dataItemList = []
        var newData = []
        function sortNumber(a, b) {
          return a.id - b.id
        }
        function randemList(a, b) {
          return Math.random()>0.5?1:-1
        }
        data.map(function (item, index) {
          item.id = parseInt(item.id)
          if (index % 100 != 0) {
            dataItemList.push(item)
            
          } else {
            if (index > 0) {
              dataItemList.sort(randemList)
              newData.push(dataItemList)
            }
            dataItemList = [item]
          }
          return item                                                                                                                                                                                                                                                                        
        })
        newData.push(dataItemList)
        // data = data.sort(sortNumber)
        // newData.sort(randemList)
        wx.setStorage({
          key: "exam",
          data: JSON.stringify(newData)
        })
      },
      fail: function (res) {

      }
    })
      //获取历史用户信息


  },
  onShow:function (opt) {
    console.log(opt)
    this.globalData.opt = opt
  },
 
  globalData: {
    userInfo: null,
    Sharing: null,
  }
})